cmake_minimum_required(VERSION 3.20)

project(CMake-check_cxx)
include(CheckCXXSourceCompiles)

set(CMAKE_CXX_STANDARD 11)

set(CHECK_CODE  
"
    #include <iostream>
    int main()
    {
        int n = 10;
        int arr[n];
        return 0;
    }
"
)
# 检测代码是否支持变长数组
check_cxx_source_compiles("${CHECK_CODE}" SUPPORT_VARRAY)
add_executable(test_compile main.cpp)

if(${SUPPORT_VARRAY})
    target_compile_definitions(test_compile PRIVATE "SUPPORT_VARRAY")
endif()

